//------------------------------------------------------------------------------
//!	@file ansi-test.c
//!	@brief
//!		ansi terminal commands test harness
//!
//!	$Id: $
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//	Copyright and Disclaimer Notice
//
//	Copyright (c) 2013 A.C. Verbeck
//
//	This file is part of ANSI: An ANSI Color Code Library.
//
//	ANSI is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	ANSI is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with ANSI.  If not, see <http://www.gnu.org/licenses/>.
//
//	This blog helped me get the ANSI color sequences working in this test:
//	http://jasonkarns.com/blog/ansi-color-in-windows-shells/
//
//	He describes a tool called ansicon.exe.  Pretty cool: makes ansi work
//	on ALL window shells...
//
//------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <popt.h>
#include <conio.h>

#include <stdint.h>									//	Standard int types
#include <stdbool.h>								//	Bool

#include "bi.h"
#include "ansiterm.h"

//----------------------------------------------------------------------------
// Local defines
//----------------------------------------------------------------------------
#define OPT_ABOUT			0x0100
#define OPT_VERBOSE			0x0200

//----------------------------------------------------------------------------
// Local data
//----------------------------------------------------------------------------
static poptContext		optCon;

//----------------------------------------------------------------------------
// Main function
//----------------------------------------------------------------------------
int main(int argc, char* argv[])
{
	uint32_t	opt=0;
	int			idx=0;

	struct poptOption optionsTable[] = {
		{ "about",	'a', POPT_ARG_NONE,	  NULL,			 'a', "display information about the app",	NULL	},
		{ "verbose",'v', POPT_ARG_NONE,	  NULL,			 'v', "enable verbose mode",				NULL	},
		POPT_AUTOHELP
		POPT_TABLEEND
	};

//----------------------------------------------------------------------------
//  Process arguments
//----------------------------------------------------------------------------
	optCon = poptGetContext(NULL, argc, (const char **)argv, optionsTable, 0);
	poptSetOtherOptionHelp(optCon, "[OPTIONS]*");

	while ((idx = poptGetNextOpt(optCon)) >= 0) {
		switch (idx) {
		case 'a':
			opt |= OPT_ABOUT;
			break;
		case 'v':
			opt |= OPT_VERBOSE;
			break;
		}
	}
	if (idx < -1) {
		fprintf(stderr, "%s: %s\n",
		        poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
		        poptStrerror(idx));
		exit(opt);
	}
	if (opt & OPT_ABOUT) {
		bldinfoPrintBldInfo();
		exit(0);
	}

//----------------------------------------------------------------------------
//  Begin the test
//----------------------------------------------------------------------------
	AnsiTerm_clr_screen();
	printf("hello world 1.1\n");
	printf("hello world 1.2\n");
	printf("hello world 1.3\n");
	printf("hello world 1.4\n");
	printf("hello world 1.5\n");
	_getch();
	AnsiTerm_clr_screen();

	printf("hello world 2.1: foreground color test\n");
	AnsiTerm_fgcolor_set(BLACK);
	printf("hello world 2.1: black test\n");
	AnsiTerm_fgcolor_set(RED);
	printf("hello world 2.1: red test\n");
	AnsiTerm_fgcolor_set(GREEN);
	printf("hello world 2.1: green test\n");
	AnsiTerm_fgcolor_set(YELLOW);
	printf("hello world 2.1: yellow test\n");
	AnsiTerm_fgcolor_set(BLUE);
	printf("hello world 2.1: blue test\n");
	AnsiTerm_fgcolor_set(MAGENTA);
	printf("hello world 2.1: magenta test\n");
	AnsiTerm_fgcolor_set(CYAN);
	printf("hello world 2.1: cyan test\n");
	AnsiTerm_fgcolor_set(WHITE);
	printf("hello world 2.1: white test\n");
	_getch();
	AnsiTerm_clr_screen();

	printf("hello world 3.1: background color test\n");
	AnsiTerm_bgcolor_set(BLACK);
	printf("hello world 3.1: black test\n");
	AnsiTerm_bgcolor_set(RED);
	printf("hello world 3.1: red test\n");
	AnsiTerm_bgcolor_set(GREEN);
	printf("hello world 3.1: green test\n");
	AnsiTerm_bgcolor_set(YELLOW);
	printf("hello world 3.1: yellow test\n");
	AnsiTerm_bgcolor_set(BLUE);
	printf("hello world 3.1: blue test\n");
	AnsiTerm_bgcolor_set(MAGENTA);
	printf("hello world 3.1: magenta test\n");
	AnsiTerm_bgcolor_set(CYAN);
	printf("hello world 3.1: cyan test\n");
	AnsiTerm_bgcolor_set(WHITE);
	printf("hello world 3.1: white test\n");
	_getch();
	AnsiTerm_clr_screen();
	AnsiTerm_clr_screen();		// this shouldn't be required...

	printf("hello world 4.1\n");
	printf("hello world 4.2\n");
	printf("hello world 4.3\n");
	printf("hello world 4.4\n");
	printf("hello world 4.5\n");
	_getch();
	AnsiTerm_clr_screen();

	printf("hello world 5.1: position tests\n");
	AnsiTerm_goto(10,5);
	printf("hello world 5.2: goto tests");
	AnsiTerm_cursor_up(2);
	printf("hello world 5.2: up tests");
	AnsiTerm_cursor_down(2);
	printf("hello world 5.2: down tests");
	AnsiTerm_cursor_fwd(2);
	printf("hello world 5.2: fwd tests");
	AnsiTerm_cursor_down(2);
	AnsiTerm_cursor_back(2);
	printf("hello world 5.2: back tests");
	_getch();
	AnsiTerm_clr_screen();

	return(0);
}

//
//  End: ansi-test.c
//
